package com.liwq.base.atomic;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @author : liwq
 * @version : 1.0
 * @date : 2023/2/1
 **/

class User{
    private int id;
    private String username;

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                '}';
    }

    public User(int id, String username) {
        this.id = id;
        this.username = username;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
}
public class AutomicUserDemo {


    public static void main(String[] args) {
        AtomicReference<User> atomicReference = new AtomicReference<>();


        User u1 = new User(1,"张三");

        User u2 = new User(2,"李四");


        atomicReference.set(u1);


        atomicReference.compareAndSet(u1,u2);
        System.out.println(atomicReference.get().toString());


    }
}
